//
//  ImformationVC.m
//  代理端
//
//  Created by sliver on 15/12/12.
//  Copyright (c) 2015年 sliver. All rights reserved.
//

#import "ImformationVC.h"
#import "Unit.h"
#import "UIImageView+WebCache.h"
@interface ImformationVC ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *tableview;
    UILabel *nameLab; //名称
    UILabel *modelLab; //内容
    NSArray *nameAry; // 名字数组
    NSDictionary *agedic; //代理商信息
    NSMutableArray *ageAry;
}
@end

@implementation ImformationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
     agedic = [[NSDictionary alloc]init];
    agedic = [NSDictionary dictionaryWithDictionary:USER_DIC];
     nameAry = @[@"公司名称",@"公司区域",@"公司地址",@"公司电话",@"公司联系人",@"公司联系人电话",@"收货地址",@"公司名称",@"公司地址",@"公司电话",@"税号",@"开户行",@"开户账号",];
    ageAry = [[NSMutableArray alloc]init];
    [ageAry addObject:agedic[@"company_name"]];
    [ageAry addObject:agedic[@"company_district"]];
    [ageAry addObject:agedic[@"company_address"]];
    [ageAry addObject:agedic[@"company_tel"]];
    [ageAry addObject:agedic[@"company_contact_name"]];
    [ageAry addObject:agedic[@"company_contact_tel"]];
    [ageAry addObject:agedic[@"deliver_address"]];
    [ageAry addObject:agedic[@"t_company_name"]];
    [ageAry addObject:agedic[@"t_company_address"]];
    [ageAry addObject:agedic[@"t_company_tel"]];
    [ageAry addObject:agedic[@"tax"]];
    [ageAry addObject:agedic[@"open_card"]];
    [ageAry addObject:agedic[@"bankcard"]];
    [self loadNav];
    [self loadView1];
    }
#pragma mark - nav
-(void)loadNav{
    self.view.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    UIView *redview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    redview.backgroundColor = DRINK_RED_COLOR;
    [self.view addSubview:redview];
    
    UILabel *redLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenW, 40)];
    redLab.backgroundColor = DRINK_RED_COLOR;
    redLab.text = @"代理商信息";
    redLab.textColor = [UIColor whiteColor];
    redLab.textAlignment =  NSTextAlignmentCenter;
    redLab.font = [UIFont boldSystemFontOfSize:19];
    [self.view addSubview:redLab];
    
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 20,44, 44)];
    backBtn.adjustsImageWhenHighlighted = NO;
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
}
-(void)loadView1{
    //背景
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 60, ScreenW, 140)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    //头像
    UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenW - 80, 70, 60, 60)];
    imgview.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    imgview.layer.masksToBounds = YES;
    imgview.layer.cornerRadius = 30;
    NSString *string =  [NSString stringWithFormat:@"%@%@",BASE_URL,USER_IMG];
    NSURL *imgurl = [NSURL URLWithString:string];
    [imgview setImageWithURL:imgurl placeholderImage:[UIImage imageNamed:@"代理商信息头像_150.png"]];
    [self.view addSubview:imgview];
    //字
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 80, 60, 20)];
    lab.font = [UIFont boldSystemFontOfSize:15];
    lab.text = @"头像";
    [self.view addSubview:lab];
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 139, ScreenW, 1)];
    view3.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    [self.view addSubview:view3];

    //账号
    
    UILabel *hanghaoLab = [[UILabel alloc]initWithFrame:CGRectMake(10, 140, 60, 30)];
    hanghaoLab.text = @"账号";
    hanghaoLab.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:hanghaoLab];

    UILabel *zhanghaoLab = [[UILabel alloc]initWithFrame:CGRectMake(ScreenW - 100, 140, 90, 30)];
    zhanghaoLab.text = CPOMANY_NAME;
    zhanghaoLab.textAlignment = NSTextAlignmentRight;
    zhanghaoLab.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:zhanghaoLab];
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 169, ScreenW, 1)];
    view2.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    [self.view addSubview:view2];
    //类别
    
    UILabel *zhanghaoLab2 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenW - 100, 170, 90, 30)];
    switch ([agedic[@"level"] integerValue]) {
        case 1:
            zhanghaoLab2.text = @"省级代理";
            break;
        case 2:
            zhanghaoLab2.text = @"市级代理";
            break;
        case 3:
            zhanghaoLab2.text = @"县级代理";
            break;
        case 4:
            zhanghaoLab2.text = @"采集客户";
            break;
            
        default:
            break;
    }
    zhanghaoLab2.textAlignment = NSTextAlignmentRight;
    zhanghaoLab2.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:zhanghaoLab2];

    
    UILabel *hanghaoLab2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 170, 100, 30)];
    hanghaoLab2.text = @"代理商类别";
    hanghaoLab2.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:hanghaoLab2];
    tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 200, ScreenW, ScreenH - 200) style:UITableViewStylePlain];
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.tableFooterView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    
    [self.view addSubview:tableview];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     NSString *cellIdStr = [NSString stringWithFormat:@"cell %lu%lu",indexPath.section,indexPath.row];
    UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:cellIdStr];
    if(!cell){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdStr];
        nameLab = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
        nameLab.font = [UIFont systemFontOfSize:14];
        nameLab.textColor = [UIColor grayColor];
        [cell.contentView addSubview:nameLab];
        
        modelLab = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, ScreenW, 20)];
        modelLab.font = [UIFont boldSystemFontOfSize:17];
        modelLab.textColor =[UIColor blackColor];
        [cell.contentView addSubview:modelLab];
        
    
    if(indexPath.section == 0){
        nameLab.text = [nameAry objectAtIndex:indexPath.row];
        modelLab.text = [ageAry objectAtIndex:indexPath.row];
    }else{
        nameLab.text = [nameAry objectAtIndex:indexPath.row + 7]
        ;
        modelLab.text = [ageAry objectAtIndex:indexPath.row + 7];
    }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
//设置cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 30)];
    lab.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    lab.textAlignment = NSTextAlignmentCenter;
    lab.font = [UIFont boldSystemFontOfSize:15];
    if(section == 0){
        lab.text = @"公司信息";
    }else{
        lab.text = @"开票信息";
    }
    return lab;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 7;
    }else{
        return 6;
    }
}
-(void)clickBack{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
